package com.itheima.controller;

import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    //跳转修改密码页
    @RequestMapping("updatePwd.html")
    public String updatePwd() {
        return "user/updatePwd";
    }

    //修改密码操作
    @PostMapping("/updatePwd")
    @ResponseBody
    public Map<String,Object> updatePwd(String username,String password,String name,String remark) {
        Map<String,Object> map = new HashMap<>();
        //调用业务层修改密码
        userService.updatePwd(username,password,name,remark);
        map.put("success",true);
        map.put("message","密码修改成功");
        return map;
    }

    //用户退出
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "redirect:/login.html";
    }

}
